/*
 *  Copyright (c) 2014 The CCP project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
 *  that can be found in the LICENSE file in the root of the web site.
 *
 *   http://www.yuntongxun.com
 *
 *  An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
package com.molichuxing.services.sdk.sms;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    public static final int DEFAULT = 0;
    public static final int YM = 1;
    public static final int YMR_SLASH = 11;
    public static final int NO_SLASH = 2;
    public static final int YM_NO_SLASH = 3;
    public static final int DATE_TIME = 4;
    public static final int DATE_TIME_NO_SLASH = 5;
    public static final int DATE_HM = 6;
    public static final int TIME = 7;
    public static final int HM = 8;
    public static final int LONG_TIME = 9;
    public static final int SHORT_TIME = 10;
    public static final int DATE_TIME_LINE = 12;

    public static String dateToStr(Date date, String pattern) {
        if ((date == null) || (date.equals(""))) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        return formatter.format(date);
    }

    public static String dateToStr(Date date) {
        return dateToStr(date, "yyyy/MM/dd");
    }

    public static String dateToStr(Date date, int type) {
        switch (type) {
            case 0:
                return dateToStr(date);
            case 1:
                return dateToStr(date, "yyyy/MM");
            case 2:
                return dateToStr(date, "yyyyMMdd");
            case 11:
                return dateToStr(date, "yyyy-MM-dd");
            case 3:
                return dateToStr(date, "yyyyMM");
            case 4:
                return dateToStr(date, "yyyy/MM/dd HH:mm:ss");
            case 5:
                return dateToStr(date, "yyyyMMddHHmmss");
            case 6:
                return dateToStr(date, "yyyy/MM/dd HH:mm");
            case 7:
                return dateToStr(date, "HH:mm:ss");
            case 8:
                return dateToStr(date, "HH:mm");
            case 9:
                return dateToStr(date, "HHmmss");
            case 10:
                return dateToStr(date, "HHmm");
            case 12:
                return dateToStr(date, "yyyy-MM-dd HH:mm:ss");
        }
        throw new IllegalArgumentException("Type undefined : " + type);
    }


//    public static Date getNowDate(String dateStr) {
//        SimpleDateFormat sdf = null;
//        try {
//            sdf = new SimpleDateFormat("yyyyMMdd");
//            Date date = sdf.parse(dateStr);
//            return date;
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        }
//    }
//
//    public static Date getDateNow(String dateStr) {
//        SimpleDateFormat sdf = null;
//        try {
//            sdf = new SimpleDateFormat("yyyy-MM-dd");
//            Date date = sdf.parse(dateStr);
//            return date;
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        }
//    }
//
//    //判断是否有效期<=当前时间+15天
//    public static boolean comparyDate(String endTime) {
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(new Date());
//        calendar.add(Calendar.DATE, 15);
//        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//        try {
//            Date endDate = df.parse(endTime);
//            if (endDate.getTime() <= calendar.getTime().getTime()) {
//                return true;
//            } else {
//                return false;
//            }
//        } catch (ParseException e) {
//            e.printStackTrace();
//            return false;
//        }
//    }
//
//    //返回n天后的某天
//    public static Date getNDays(int n) {
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(new Date());
//        calendar.add(Calendar.DATE, n);
//        return calendar.getTime();
//    }
//
//    public static void deleteFile(String fileName) {
//        File file = new File(fileName);
//        if (file.exists()) {
//            file.delete();
//        }
//    }
//
//    //返回年后的某天
//    public static Date getNYears(int n, String beginTime) {
//        beginTime = formatDate(beginTime);
//        DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
//        try {
//            Date beginDate = format1.parse(beginTime);
//            Calendar calendar = Calendar.getInstance();
//            calendar.setTime(beginDate);
//            calendar.add(Calendar.YEAR, n);
//            return calendar.getTime();
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        return new Date();
//    }
//
//
//    public static String formatDate(String dateStr) {
//        if (dateStr.length() >= 19) {
//            dateStr = dateStr.substring(0, 10);
//        }
//        if (dateStr.length() == 8) {
//            dateStr = dateStr.substring(0, 4) + "-" + dateStr.substring(4, 6) + "-" + dateStr.substring(6, 8);
//        }
//        return dateStr;
//    }


}